
package com.probiz.estoresa.customer.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.customer.Feedback;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.customer.model.FeedbackSearchCriteria;
import com.probiz.estore.customer.service.FeedbackManager;

public class FeedbackReplyController extends GenericStoreAdminController<Feedback> {
	private FeedbackManager		feedbackManager	= null;
	public void setFeedbackManager(FeedbackManager feedbackManager) {
		this.feedbackManager = feedbackManager;
	}
	@Override
	protected String getEntityName(Feedback entity) {
		return null;
	}



	@Override
	protected void initController() throws Exception {
		mgr = feedbackManager;
	}

	@Override
	protected void preSave(HttpServletRequest request, Feedback entity, BindException errors) {
		
	}
	
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/feedbackReplyList");
		mv.addObject("parentId", request.getParameter("parentId"));
		return mv;
	}
	
	public ModelAndView search(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/include/feedbackReplyListBody");
		SearchCriteria searchCriteria = createSearchCriteria(request);
		FeedbackSearchCriteria feedbackSearchCriteria = new FeedbackSearchCriteria();
		try {
			// 绑定参数
			bind(request, feedbackSearchCriteria);
			List<Feedback> feedbackList = feedbackManager.searchByCriteriaForController(feedbackSearchCriteria,searchCriteria);
			mv.addObject("feedbackList", feedbackList);
			mv.addObject("feedbackSearchCriteria", feedbackSearchCriteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	/**
	 * 切换可见隐藏
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView multiToggleShowStatus(HttpServletRequest request,	HttpServletResponse response) {
		String[] ids = request.getParameterValues("multiIds");
		if (ids != null && ids.length > 0) {
			for (String entityId : ids) {
				Feedback feedback = feedbackManager.getById(Integer.valueOf(entityId));
				if(!feedback.getStatus().equals(Feedback.STATUS_SHOW)){
					feedbackManager.doMarkShow(feedback);
				}else{
					feedbackManager.doMarkUnShow(feedback);
				}
			}
		}
		return null;
	}
	
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView multiDelete(HttpServletRequest request,	HttpServletResponse response) {
		String[] ids = request.getParameterValues("multiIds");
		if (ids != null && ids.length > 0) {
			for (String entityId : ids) {
				Feedback feedback  = feedbackManager.getById(Integer.valueOf(entityId));
				feedbackManager.deleteFully(feedback);
			}
		}
		return null;
	}
	

	

}
